//
//  lanViewController.m
//  BAOASystem
//
//  Created by michael on 2018/4/18.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "lanViewController.h"
#import "MainTabBarController.h"

@interface lanViewController ()

@end

@implementation lanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    image.image = [UIImage imageNamed:@"登录-背景"];
    [self.view addSubview:image];
     UIImageView *logoimage = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth/2-50,40 , 100, 100)];
    logoimage.image = [UIImage imageNamed:@"登录-logo"];
    [self.view addSubview:logoimage];
      UIImageView *titleimage = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth/2-120,logoimage.bottom+10 , 240, 60)];
    titleimage.image = [UIImage imageNamed:@"img_login_title"];
    [self.view addSubview:titleimage];
    UILabel *label = [[UILabel alloc]init];
    label.frame = CGRectMake(KScreenWidth/2-120, KScreenHeight/2, 240, 40);
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment  = 1;
label.text = @"请选择语言";
label.font = [UIFont systemFontOfSize: 24.0];
label.textColor = [UIColor blackColor];
[self.view addSubview:label];
 UILabel *elabel = [[UILabel alloc]init];
    elabel.frame = CGRectMake(KScreenWidth/2-150, label.bottom+20, 300, 40);
    elabel.backgroundColor = [UIColor clearColor];
    elabel.textAlignment  = 1;
elabel.text = @"Please select the language";
elabel.font = [UIFont systemFontOfSize: 24.0];
elabel.textColor = [UIColor blackColor];
[self.view addSubview:elabel];


 UIButton *cbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    cbutton.frame = CGRectMake(KScreenWidth/2-150, elabel.bottom+10, 300,40);
    [cbutton setTitle:@"中文/Chinese" forState:UIControlStateNormal];
    [cbutton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    cbutton.titleLabel.font = [UIFont systemFontOfSize: 20.0];
        [cbutton addTarget:self action:@selector(caction) forControlEvents:UIControlEventTouchUpInside];
        cbutton.backgroundColor = [UIColor whiteColor];
 [cbutton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  cbutton.layer.cornerRadius = cbutton.height/2;
[self.view addSubview:cbutton];
 UIButton *ebutton = [UIButton buttonWithType:UIButtonTypeCustom];
    ebutton.frame = CGRectMake(KScreenWidth/2-150, cbutton.bottom+20, 300,40);
    [ebutton setTitle:@"英文/English" forState:UIControlStateNormal];
    [ebutton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
    ebutton.titleLabel.font = [UIFont systemFontOfSize: 20.0];
    ebutton.backgroundColor = [UIColor whiteColor];
        [ebutton addTarget:self action:@selector(eaction) forControlEvents:UIControlEventTouchUpInside];
 [ebutton setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
  ebutton.layer.cornerRadius = ebutton.height/2;
[self.view addSubview:ebutton];
    // Do any additional setup after loading the view.
}
- (void)caction{
    [self changeLanguageTo:@"zh-Hans"];

  [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"language"];
                          [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"website"];
MainTabBarController *tar = [[MainTabBarController alloc]init];

                   self.view.window.rootViewController = tar;

}
- (void)eaction{
//[self.view makeToast:NSLocalizedString(@"正在内测中",nil)];
    [self changeLanguageTo:@"en"];
      [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"language"];
     [[NSUserDefaults standardUserDefaults] setObject:@"2" forKey:@"website"];
     MainTabBarController *tar = [[MainTabBarController alloc]init];

                   self.view.window.rootViewController = tar;



}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)changeLanguageTo:(NSString *)language {
    // 设置语言
    [NSBundle setLanguage:language];
    
    // 然后将设置好的语言存储好，下次进来直接加载
    [[NSUserDefaults standardUserDefaults] setObject:language forKey:@"myLanguage"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    // 我们要把系统windown的rootViewController替换掉
//    ZHTabBarController *tab = [[ZHTabBarController alloc] init];
//    [UIApplication sharedApplication].keyWindow.rootViewController = tab;
//    // 跳转到设置页
//    tab.selectedIndex = 2;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
